from modelscope.hub.api import HubApi
from modelscope.hub.constants import Licenses, ModelVisibility
import os

YOUR_ACCESS_TOKEN = os.environ["MODEL_SCOPE_API_KEY"]

api = HubApi()
api.login(YOUR_ACCESS_TOKEN)

username = 'taxuepiaoyi'
model_name = 'qwen2.5_7B_traditional_chinese_medicine'
repo_id = f"{username}/{model_name}"

# 检查项目是否存在，如果不存在则创建
try:
    api.get_model(repo_id)
except Exception as e:
    print(f"项目不存在，创建新项目: {repo_id}")
    api.create_model(
        model_id=repo_id,
        visibility=ModelVisibility.PUBLIC,  # 或PRIVATE
        license='apache-2.0'
    )

# 使用upload_folder上传模型
api.upload_folder(
    repo_id=repo_id,
    folder_path="/Volumes/work/ai-download/models/qwen2_5_lora_sft",
    commit_message="Upload model"
)